<template>
  <a-modal v-model="currentLogVisible" width="700px" :footer="null" title="日志" @cancel="currentLogVisible = false">
    <a-table bordered :columns="columns" :rowKey="record => record.id" :data-source="logList" :pagination="pagination" :scroll="{ x: true }" @change="handleTableChange">
      <span slot="optType" slot-scope="text">
        <span v-if="text == 0">编辑</span>
        <span v-if="text == 1">上架</span>
        <span v-if="text == 2">下架</span>
        <span v-if="text == 3">删除</span>
      </span>
    </a-table>
  </a-modal>
</template>
<script>
import { queryOperateTask } from '@/api/marketingCenter/memberTask'
const columns = [
  {
    title: '操作类型',
    dataIndex: 'optType',
    scopedSlots: { customRender: 'optType' }
  },
  {
    title: '时间',
    dataIndex: 'createTime'
  },
  {
    title: '操作人',
    dataIndex: 'operatorName'
  }
]
export default {
  props: {
    logVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      columns,
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '40'],
        showSizeChanger: true,
        showTotal: total => `共 ${total} 条记录`,
        itemRender: (current, type, originalElement) => {
          if (type === 'prev') {
            return <a>上一页</a>
          } else if (type === 'next') {
            return <a>下一页</a>
          }
          return originalElement
        }
      },
      id: '',
      logList: []
    }
  },
  computed: {
    currentLogVisible: {
      get() {
        return this.logVisible
      },
      set(val) {
        this.$emit('update:logVisible', val)
      }
    }
  },
  created() {},
  methods: {
    handleTableChange(pagination) {
      this.pagination = pagination
      this.getLog(this.id)
    },
    getLog(id, parent) {
      this.id = id
      if (parent) {
        this.pagination.current = 1
      }
      this.logList = []
      const { current, pageSize } = this.pagination
      const data = {
        requestData: {
          taskId: this.id
        },
        page: {
          pageNo: current,
          pageSize
        }
      }
      queryOperateTask(data).then(res => {
        if (res.code == 0) {
          const { total } = res.page
          this.logList = res.data || []
          this.pagination.total = total || 0
        } else {
          this.$message.warning(res.msg)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped></style>

